from sqlalchemy import create_engine, Column, Integer, String, Json, PickleType
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import json
engine = create_engine('sqlite:///clickDataBase/DataRes/click.db', echo=True)
Base = declarative_base()
Session = sessionmaker(bind=engine)
session= Session()

class TreeJson(Base):
    __tablename__ = 'click'
    id = Column(String, primary_key=True)
    click_list=Column(PickleType)
Base.metadata.create_all(engine)

def addClick(id,click_list):
    new_click = Click(id=id, click_list=click_list)
    session.add(new_click)
    session.commit()

def updateClick(id,location):
    click = session.query(TreeJson).filter_by(id=id).first()
    click.click_list[location]+=1
    session.commit()